<div class="member-main">
  <div id="tab-onsell" class="section switch">
    <ul class="switchable-triggerBox clearfix">
      <li class="active"><a href="#"><{t}>出售中的宝贝<{/t}></a></li>
    </ul>
    <div class="switchable-content" >
      <div class="switchable-panel">
        <{if !$goods}>
        <div class="noinfo"><{t}>暂无商品<{/t}></div>
        <{/if}>
        <div class="search-form">
          <div>
            <div class="colum">
              <p class="row">
                <label for="search-keyword"><{t}>宝贝名称：<{/t}></label>
                <input id="search-keyword" type="text" name="content[name]" maxlength="64" value="">
              </p>
              <p class="row">
                <label><{t}>价格：<{/t}></label>
                <input id="search-price-from" type="text" name="content[price_from]" value="" vtype="number">
                <{t}> 到 <{/t}>
                <input id="search-price-to" type="text" name="content[price_to]" value="" vtype="number">
              </p>
            </div>
            <div class="colum">
              <p class="row">
                <label for="outer-id"><{t}>商家编码：<{/t}></label>
                <input id="outer-id" type="text" name="content[bn]" maxlength="64" value="">
              </p>
              <p class="row">
                <label><{t}>总销量：<{/t}></label>
                <input id="search-num-from" type="text" name="content[bcount_from]" value="" vtype="number">
                <{t}> 到 <{/t}>
                <input id="search-num-to" type="text" name="content[bcount_to]" value="" vtype="number">
              </p>
            </div>
            <div class="colum">
              <p class="row">
                <label for="first-cate-id"><{t}>一级类目：<{/t}></label>
                <{input id="first-cate-id" type="select" name="content[cat_id]" style="font-size:12px;" value="" rows=$catList valueColumn="cat_id" labelColumn="cat_name"}>
              </p>              
            </div>
			 <p class="submitArea" style="float:left;">
            <button class="btn submit-btn" onclick="searchItems()" type="button"><{t}>搜索<{/t}></button>
          </p>
			<div class="crl"></div>
			<div class="colum">
				<p class="row">
                <label for="simselect"><{t}>店铺中的分类：<{/t}></label>
                <{input id="simselect" type="select" name="content[custom_cat_id]" value="" rows=$customcatList valueColumn="cat_id" labelColumn="cat_name"}>
              </p>
			</div>
			<div class="crl"></div>
          </div>
         
        </div>
        <{include file="site/member/goods_list.html" app="business"}>
      </div>
    </div>
  </div>
</div>
<script>
  var item = $$('#J_DataTable input[name^=item[]')||[];
  var all = $$('#J_DataTable .all-selector')||[];
  window.addEvent('domready', function(){
    if(item)
      item.set('checked', !!$ES('#J_DataTable .all-selector').checked);
    if(all)
      all.removeEvents('click').addEvent('click',function(e){
        var target=$(e.target);
        all.set('checked', !!target.checked);
        if(item) item.set('checked', !!target.checked);
        $ES('#switchable input[name^=operate]').set('value', !!target.checked);
      });
  });
  function isSelected(){
    if(!item) return false;
    for(i=0;i<item.length;i++){
      if(item[i].checked){
        return true;
      }
    }
    if(!all) return false;
    for(i=0;i<all.length;i++){
      if(all[i].checked){
        return true;
      }
    }
    return false;
  }
  
  function deleteItem(){
    if(!isSelected()){
      Ex_Dialog.alert('请选中要删除的宝贝！');
      return false;
    }
    Ex_Dialog.confirm('确认删除宝贝？',function(e){
      if(!e) return false;
      new Request.JSON({
        url:'<{link app=business ctl=site_member act=goods_delete arg=onsell}>',
        method:'post',
        secure:false,
        data:$('tab-onsell'),
        onComplete:function(res,text){
          if (res.error){
            Message.error(res.error);
          }else{
            if (!res.data&&res.reload != null){
              location.href=res.reload;
            }else{
              var js='';
              var html = res.data.stripScripts(function(script){
                  js = script;
              });

              $('J_DataTable').innerHTML = html;
              Browser.exec(js);
              return;
            }
          }
        }
      }).send();
      return false;
    });
  }
  function offShelf(){
    if(!isSelected()){
      Ex_Dialog.alert('请选中要下架的宝贝！');
      return false;
    }
    Ex_Dialog.confirm('确认下架宝贝？',function(e){
      if(!e) return false;
      new Request.JSON({
        url:'<{link app=business ctl=site_member act=goods_enabled arg=onsell}>',
        method:'post',
        secure:false,
        data:$('tab-onsell'),
        onComplete:function(res,text){
          if (res.error){
            Message.error(res.error);
          }else{
            if (!res.data&&res.reload != null){
              location.href=res.reload;
            }else{
              var js='';
              var html = res.data.stripScripts(function(script){
                  js = script;
              });

              $('J_DataTable').innerHTML = html;
              Browser.exec(js);
              return;
            }
          }
        }
      }).send();
      return false;
    });
  }
  
  function searchItems(){
    new Request.JSON({
      url:'<{link app=business ctl=site_member act=goods_search arg=onsell}>',
      method:'post',
      secure:false,
      data:$('tab-onsell'),
      onComplete:function(res,text){
        if (res.error){
          Message.error(res.error);
        }else{
          if (!res.data&&res.reload != null){
            location.href=res.reload;
          }else{
            var js='';
            var html = res.data.stripScripts(function(script){
                js = script;
            });

            $('J_DataTable').innerHTML = html;
            Browser.exec(js);
            return;
          }
        }
      }
    }).send();
  } 
</script>